package com.notemanagement.ui;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.TextView;

import com.notemanagement.R;
import com.notemanagement.bean.OrderDetailInfo;

import org.w3c.dom.Text;

import java.net.URI;

/**
 * Created by 金 on 2015/1/17.
 */
public class OrderDetail extends Activity implements View.OnClickListener, View.OnLongClickListener {
    private TextView name, phone, address, date, product1, num1, product2, num2, product3, num3, product4, num4, product5, num5;
    private ImageView back_image;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.order_detail);

        initView();
    }

    private void initView() {
        back_image = (ImageView) findViewById(R.id.order_detail_head_back);
        name = (TextView) findViewById(R.id.order_detail_name);
        phone = (TextView) findViewById(R.id.order_detail_phone);
        address = (TextView) findViewById(R.id.order_detail_address);
        date = (TextView) findViewById(R.id.order_detail_date);
        product1 = (TextView) findViewById(R.id.order_detail_product1);
        product2 = (TextView) findViewById(R.id.order_detail_product2);
        product3 = (TextView) findViewById(R.id.order_detail_product3);
        product4 = (TextView) findViewById(R.id.order_detail_product4);
        product5 = (TextView) findViewById(R.id.order_detail_product5);
        num1 = (TextView) findViewById(R.id.order_detail_product1_num);
        num2 = (TextView) findViewById(R.id.order_detail_product2_num);
        num3 = (TextView) findViewById(R.id.order_detail_product3_num);
        num4 = (TextView) findViewById(R.id.order_detail_product4_num);
        num5 = (TextView) findViewById(R.id.order_detail_product5_num);

        back_image.setOnClickListener(this);
        phone.setOnLongClickListener(this);


        Intent intent = getIntent();
        Bundle bundle = intent.getBundleExtra("bundle");
        OrderDetailInfo info = (OrderDetailInfo) bundle.getSerializable("detail");
        Log.d("king", "name = " + info.name);
        name.setText(info.name);
        phone.setText(info.phone);
        address.setText(info.address);
        date.setText(info.date.substring(0, 4) + "-" + info.date.substring(4, 6) + "-" + info.date.substring(6));
        product1.setText(info.materials.get(0));
        Log.d("king", "num1 = " + info.materialNum.get(0));
        num1.setText(info.materialNum.get(0) + "");
        if (!info.materials.get(1).equals("")) {
            product2.setText(info.materials.get(1));
            num2.setText(info.materialNum.get(1) + "");
        }
        if (!info.materials.get(2).equals("")) {
            product3.setText(info.materials.get(2));
            num3.setText(info.materialNum.get(2) + "");
        }
        if (!info.materials.get(3).equals("")) {
            product4.setText(info.materials.get(3));
            num4.setText(info.materialNum.get(3) + "");
        }
        if (!info.materials.get(4).equals("")) {
            product5.setText(info.materials.get(4));
            num5.setText(info.materialNum.get(4) + "");
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.order_detail_head_back:
                this.finish();
                break;
        }
    }

    @Override
    public boolean onLongClick(View v) {
        switch (v.getId()) {
            case R.id.order_detail_phone:
                Intent intent = new Intent(Intent.ACTION_CALL,
                        Uri.parse("tel:" + phone.getText().toString().trim()));
                startActivity(intent);
                break;

        }

        return true;
    }
}
